package com.hujf.mapreduce.writeable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author Hujf
 * @title: FlowReducer
 * @date 2021/3/3017:29
 * @description: TODO
 */
public class FlowReducer extends Reducer<Text, FlowBean,Text, FlowBean> {

    private FlowBean bean = new FlowBean();
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        long uplong = 0;
        long downlong =0;
        //遍历
        for (FlowBean value : values) {
            uplong+=value.getUpFlow();
            downlong+=value.getDownFlow();
        }
        bean.setUpFlow(uplong);
        bean.setDownFlow(downlong);
        bean.setTotal();
        context.write(key,bean);
    }
}
